package com.epalmpay.service.jobservice.impl;

import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.util.DateUtil;
import com.epalmpay.util.SysUtils;
import com.epalmpay.bean.ChargeOrderBean;
import com.epalmpay.bean.StatisChargeReportBean;
import com.epalmpay.dto.datareport.BaseReportInDTO;
import com.epalmpay.dto.datareport.ChargeReportExportListOutDTO;
import com.epalmpay.dto.datareport.ChargeReportInfoListOutDTO;
import com.epalmpay.dto.datareport.ChargeReportListOutDTO;
import com.epalmpay.entity.*;
import com.epalmpay.enumdef.BizEnum.PaymentScene;
import com.epalmpay.enumdef.BizEnum.PaymentType;
import com.epalmpay.enumdef.BizEnum.TransactionType;
import com.epalmpay.enumdef.CommonEnum.RunStatus;
import com.epalmpay.enumdef.CommonEnum.TaskType;
import com.epalmpay.mapper.*;
import com.epalmpay.service.jobservice.ITradeStatisService;
import com.epalmpay.service.order.IOrderService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wzq on 2017/6/14.
 */
@Service("tradeStatisServiceImpl")
public class TradeStatisServiceImpl implements ITradeStatisService {
	@Resource
	private StatisMemberDayMapper statisMemberDayMapper;
	@Resource
	private StatisShopDayMapper statisShopDayMapper;
	@Resource
	private StatisAgentDayMapper statisAgentDayMapper;
	@Resource
	private StatisGroupDayMapper statisGroupDayMapper;
	@Resource
	private StatisEpalmpayDayMapper statisEpalmpayDayMapper;

	//月统计mapper
	@Resource
	private StatisMemberMonthMapper statisMemberMonthMapper;
	@Resource
	private StatisShopMonthMapper statisShopMonthMapper;
	@Resource
	private StatisAgentMonthMapper statisAgentMonthMapper;
	@Resource
	private 	StatisGroupMonthMapper statisGroupMonthMapper;
	@Resource
	private	StatisEpalmpayMonthMapper statisEpalmpayMonthMapper;
	@Resource
	private StatisChargeMapper statisChargeMapper;
	@Resource
	StatisMemberMapper statisMemberMapper;
	@Resource
	StatisShopMapper statisShopMapper;
	@Resource
	StatisAgentMapper statisAgentMapper;
	@Resource
	StatisGroupMapper statisGroupMapper;
	@Resource
	StatisEpalmpayMapper statisEpalmpayMapper;
	@Resource
    private SysTaskLogMapper sysTaskLogMapper;
	@Resource
	private BonusVerifyShopMapper bonusVerifyShopMapper;
	@Resource
	private BonusSendShopMapper bonusSendShopMapper;
	@Resource
	private BonusVerifyShopMonthMapper bonusVerifyShopMonthMapper;
	@Resource
	private BonusSendShopMonthMapper bonusSendShopMonthMapper;
    @Resource
	private TradeOfflineMapper tradeOfflineMapper;
	@Resource
	private IOrderService iOrderService;


    //交易日统计
	public int saveTradeDayStatis(Date statisDate) throws Exception{
		int result=0;
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("taskType", TaskType.TradeDayStatis.getType());
		param.put("taskDate", statisDate);

		SysTaskLog oldRecord = sysTaskLogMapper.selectSysTaskLogByTypeAndDate(param);
		if(oldRecord  != null && oldRecord.getResultStatus() == RunStatus.Success.getType()){
			throw new ApplicationException(Rescode.FAIL,"计划任务已经执行成功！");
		}
		StringBuffer sb = new StringBuffer();

		//门店本月核销积分统计
		result = bonusVerifyShopMapper.insertThisMonthVerifyBonus(statisDate);
		sb.append("本次任务日统计【门店本月核销积分】影响的行数：").append(result);

		//门店本月发送积分(已入账的记录)
		result = bonusSendShopMapper.insertThisMonthSendBonus(statisDate);
		sb.append("本次任务日统计【门店本月发送积分】影响的行数：").append(result);


		//会员日统计
		result = statisMemberDayMapper.insertDayStatis(statisDate);
		sb.append("本次任务日统计【会员日统计】影响的行数：").append(result);
		result = statisMemberMapper.insertThisMonthStatis(statisDate);

		result = statisMemberMapper.insertThisMonthBonusStatis(statisDate);
		//门店日统计
		result = statisShopDayMapper.insertDayStatis(statisDate);
		sb.append(";本次任务日统计【门店日统计】影响的行数：").append(result);
		result = statisShopMapper.insertThisMonthStatis(statisDate);
        //代理日统计
		result = statisAgentDayMapper.insertDayStatis(statisDate);
		result = statisAgentMapper.insertThisMonthStatis(statisDate);
		sb.append(";本次任务日统计【代理日统计】影响的行数：").append(result);
		result = statisGroupDayMapper.insertDayStatis(statisDate);
		result = statisGroupMapper.insertThisMonthStatis(statisDate);
		sb.append(";本次任务日统计【大商户日统计】影响的行数：").append(result);
		result = statisEpalmpayDayMapper.insertDayStatis(statisDate);
		result = statisEpalmpayMapper.insertThisMonthStatis(statisDate);
		sb.append(";本次任务日统计【掌富日统计】影响的行数：").append(result);

		if(oldRecord  == null){
			SysTaskLog record = new SysTaskLog();
			record.setGmtCreate(new Date());
			record.setGmtModified(new Date());
			record.setTaskType(TaskType.TradeDayStatis.getType());
			record.setTaskDate(statisDate);
			record.setResultStatus(RunStatus.Success.getType());
			record.setRunTimes(0);
			record.setMemo(sb.toString());
			result = sysTaskLogMapper.insert(record);
		}
		else{
			oldRecord.setGmtModified(new Date());
			oldRecord.setResultStatus(RunStatus.Success.getType());
			oldRecord.setRunTimes((oldRecord.getRunTimes()==null?0:oldRecord.getRunTimes())+1);
			oldRecord.setMemo(sb.toString());
			result = sysTaskLogMapper.updateByPrimaryKeySelective(oldRecord);
		}

		return result;
	}

	//交易月统计
	public int saveTradeMonthStatis(Date statisDate) throws Exception{
		int result=0;
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("taskType", TaskType.TradeMonthStatis.getType());
		param.put("taskDate", statisDate);

		SysTaskLog oldRecord = sysTaskLogMapper.selectSysTaskLogByTypeAndDate(param);
		if(oldRecord  != null && oldRecord.getResultStatus() == RunStatus.Success.getType()){
			throw new ApplicationException(Rescode.FAIL,"计划任务已经执行成功！");
		}
		StringBuffer sb = new StringBuffer();

		//插入门店核销积分月统计
		result = bonusVerifyShopMonthMapper.insertShopVerifyBonusMonthStatics(statisDate);
		sb.append("本次任务日统计【门店核销积分月统计】影响的行数：").append(result);
		//插入门店发送积分月统计
		result = bonusSendShopMonthMapper.insertShopSendBonusMonthStatics(statisDate);
		sb.append("本次任务日统计【门店发送积分月统计】影响的行数：").append(result);

		//插入月统计
		result = statisMemberMonthMapper.insertMonthStatis(statisDate);
		sb.append("本次任务日统计【会员月统计】影响的行数：").append(result);
		result = statisMemberMapper.insertLastMonthStatis(statisDate);
		//统计最后一个月总分润
		result = statisMemberMapper.insertLastMonthProfitStatis(statisDate);
		result = statisShopMonthMapper.insertMonthStatis(statisDate);
		sb.append(";本次任务日统计【门店月统计】影响的行数：").append(result);
		result = statisShopMapper.insertLastMonthStatis(statisDate);
		result = statisAgentMonthMapper.insertMonthStatis(statisDate);
		sb.append(";本次任务日统计【代理月统计】影响的行数：").append(result);
		result = statisAgentMapper.insertLastMonthStatis(statisDate);
		result = statisGroupMonthMapper.insertMonthStatis(statisDate);
		sb.append(";本次任务日统计【大商户月统计】影响的行数：").append(result);
		result = statisGroupMapper.insertLastMonthStatis(statisDate);
		result = statisEpalmpayMonthMapper.insertMonthStatis(statisDate);
		sb.append(";本次任务日统计【掌富月统计】影响的行数：").append(result);
		result = statisEpalmpayMapper.insertLastMonthStatis(statisDate);

		//插入计划任务成功日志
		if(oldRecord  == null){
			SysTaskLog record = new SysTaskLog();
			record.setGmtCreate(new Date());
			record.setGmtModified(new Date());
			record.setTaskType(TaskType.TradeMonthStatis.getType());
			record.setTaskDate(statisDate);
			record.setResultStatus(RunStatus.Success.getType());
			record.setRunTimes(0);
			record.setMemo(sb.toString());
			result = sysTaskLogMapper.insert(record);
		}
		else{
			oldRecord.setGmtModified(new Date());
			oldRecord.setResultStatus(RunStatus.Success.getType());
			oldRecord.setRunTimes((oldRecord.getRunTimes()==null?0:oldRecord.getRunTimes())+1);
			oldRecord.setMemo(sb.toString());
			result = sysTaskLogMapper.updateByPrimaryKeySelective(oldRecord);
		}

		return result;
	}

	public int serviceGoodVerifyOutMontyDay(Date statisDate) throws Exception{
		int result = 0;

		Map<String,Object> param=new HashMap<String,Object>();
		param.put("taskType", TaskType.ServiceGoodVerifyOutMontyDay.getType());
		param.put("taskDate", statisDate);

		SysTaskLog oldRecord = sysTaskLogMapper.selectSysTaskLogByTypeAndDate(param);
		if(oldRecord  != null && oldRecord.getResultStatus() == RunStatus.Success.getType()){
			//可以重复执行
			//throw new ApplicationException(Rescode.FAIL,"计划任务已经执行成功！");
		}
		StringBuffer sb = new StringBuffer();

		result = iOrderService.serviceGoodVerifyOutMontyDay(statisDate);
		sb.append(";本次任务日统计【核销日出款】影响的行数：").append(result);

		if(oldRecord  == null){
			SysTaskLog record = new SysTaskLog();
			record.setGmtCreate(new Date());
			record.setGmtModified(new Date());
			record.setTaskType(TaskType.ServiceGoodVerifyOutMontyDay.getType());
			record.setTaskDate(statisDate);
			record.setResultStatus(RunStatus.Success.getType());
			record.setRunTimes(0);
			record.setMemo(sb.toString());
			result = sysTaskLogMapper.insert(record);
		}
		else{
			oldRecord.setGmtModified(new Date());
			oldRecord.setResultStatus(RunStatus.Success.getType());
			oldRecord.setRunTimes((oldRecord.getRunTimes()==null?0:oldRecord.getRunTimes())+1);
			oldRecord.setMemo(sb.toString());
			result = sysTaskLogMapper.updateByPrimaryKeySelective(oldRecord);
		}

		return result;
	}

	@Override
	public int finishCouponMerchantSetted(Date statisDate) throws Exception{
			int result = 0;

			Map<String,Object> param=new HashMap<String,Object>();
			param.put("taskType", TaskType.CouponMerchantSetted.getType());
			param.put("taskDate", statisDate);

			SysTaskLog oldRecord = sysTaskLogMapper.selectSysTaskLogByTypeAndDate(param);
			if(oldRecord  != null && oldRecord.getResultStatus() == RunStatus.Success.getType()){
				//可以重复执行
				//throw new ApplicationException(Rescode.FAIL,"计划任务已经执行成功！");
			}
			StringBuffer sb = new StringBuffer();

			result = iOrderService.finishCouponMerchantSetted(statisDate);
			
			sb.append(";本次任务日统计【核销日出款】影响的行数：").append(result);

			if(oldRecord  == null){
				SysTaskLog record = new SysTaskLog();
				record.setGmtCreate(new Date());
				record.setGmtModified(new Date());
				record.setTaskType(TaskType.CouponMerchantSetted.getType());
				record.setTaskDate(statisDate);
				record.setResultStatus(RunStatus.Success.getType());
				record.setRunTimes(0);
				record.setMemo(sb.toString());
				result = sysTaskLogMapper.insert(record);
			}
			else{
				oldRecord.setGmtModified(new Date());
				oldRecord.setResultStatus(RunStatus.Success.getType());
				oldRecord.setRunTimes((oldRecord.getRunTimes()==null?0:oldRecord.getRunTimes())+1);
				oldRecord.setMemo(sb.toString());
				result = sysTaskLogMapper.updateByPrimaryKeySelective(oldRecord);
			}

			return result;
		}
	
	@Override
	public int finishGoodsMerchantSetted(Date statisDate) throws Exception{
			int result = 0;

			Map<String,Object> param=new HashMap<String,Object>();
			param.put("taskType", TaskType.CouponMerchantSetted.getType());
			param.put("taskDate", statisDate);

			SysTaskLog oldRecord = sysTaskLogMapper.selectSysTaskLogByTypeAndDate(param);
			if(oldRecord  != null && oldRecord.getResultStatus() == RunStatus.Success.getType()){
				//可以重复执行
				//throw new ApplicationException(Rescode.FAIL,"计划任务已经执行成功！");
			}
			StringBuffer sb = new StringBuffer();

			result = iOrderService.finishGoodsMerchantSetted(statisDate);
			
			sb.append(";本次任务日统计【核销日出款】影响的行数：").append(result);

			if(oldRecord  == null){
				SysTaskLog record = new SysTaskLog();
				record.setGmtCreate(new Date());
				record.setGmtModified(new Date());
				record.setTaskType(TaskType.CouponMerchantSetted.getType());
				record.setTaskDate(statisDate);
				record.setResultStatus(RunStatus.Success.getType());
				record.setRunTimes(0);
				record.setMemo(sb.toString());
				result = sysTaskLogMapper.insert(record);
			}
			else{
				oldRecord.setGmtModified(new Date());
				oldRecord.setResultStatus(RunStatus.Success.getType());
				oldRecord.setRunTimes((oldRecord.getRunTimes()==null?0:oldRecord.getRunTimes())+1);
				oldRecord.setMemo(sb.toString());
				result = sysTaskLogMapper.updateByPrimaryKeySelective(oldRecord);
			}

			return result;
		}
	
	

	@Override
	public void saveChargeDayStatis(Date statisDate) throws Exception {

		String statisDateStr = DateUtil.fomatDate(statisDate, DateUtil.sdfDay);

		List<Long> groupIds = tradeOfflineMapper.findGroupIdChargeOrder(statisDateStr);
		for (Long groupId : groupIds) {
			StatisCharge statisCharge = statisChargeMapper.selectByStatisDate(statisDateStr, groupId);

			if (statisCharge == null) {
				statisCharge = new StatisCharge();
				statisCharge.setDay(statisDateStr);
				statisCharge.setGmtCreate(new Date());
				statisCharge.setGmtModified(new Date());
				statisCharge.setGroupId(groupId);
				statisCharge.setActulChargeAmount(0L);
				statisCharge.setAlipayChargeAmount(0L);
				statisCharge.setAlipayChargeCount(0);
				statisCharge.setAlipayotherChargeAmount(0L);
				statisCharge.setAlipayotherChargeCount(0);
				statisCharge.setAlipayposChargeAmount(0L);
				statisCharge.setAlipayposChargeCount(0);
				statisCharge.setChargeAmount(0l);
				statisCharge.setChargeCount(0);
				statisCharge.setChargedChargeAmount(0L);
				statisCharge.setChargedChargeCount(0);
				statisCharge.setNetbankChargeAmount(0);
				statisCharge.setNetbankChargeCount(0);
				statisCharge.setPosbankChargeAmount(0L);
				statisCharge.setPosbankChargeCount(0);
				statisCharge.setPoscashChargeAmount(0L);
				statisCharge.setPoscashChargeCount(0);
				
				statisCharge.setPoscashChargeCount(0);
				statisCharge.setPoscashChargeAmount(0L);
				statisCharge.setPoscashChargeCount(0);
				
				statisCharge.setRedpackageChargeAmount(0L);
				statisCharge.setRedpackageChargeCount(0);
				statisCharge.setSaleChargeAmount(0L);
				statisCharge.setSaleChargeCount(0);
				statisCharge.setWxpayChargeAmount(0L);
				statisCharge.setWxpayChargeCount(0);
				statisCharge.setWxpayotherChargeAmount(0L);
				statisCharge.setWxpayotherChargeCount(0);
				statisCharge.setWxpayposChargeAmount(0L);
				statisCharge.setWxpayposChargeCount(0);
			}
			// 查询 充值 ，消费送 ，充值送 红包送 的交易
			List<Map<String, Object>> result = tradeOfflineMapper.selectStaticChargeGroupByTransactionType(statisDateStr, statisDateStr, groupId);
			for (Map<String, Object> map : result) {
				if (TransactionType.RedPackage.getType() == SysUtils.Object2int(map.get("transaction_type"))) {
					statisCharge.setChargeAmount(statisCharge.getChargeAmount() + SysUtils.Object2Long(map.get("payAmount")));
					statisCharge.setChargeCount(statisCharge.getChargeCount() + SysUtils.Object2int(map.get("payCount")));
					statisCharge.setRedpackageChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
					statisCharge.setRedpackageChargeCount(SysUtils.Object2int(map.get("payCount")));
				} else if (TransactionType.Recharge.getType() == SysUtils.Object2int(map.get("transaction_type"))) {

					statisCharge.setChargeAmount(statisCharge.getChargeAmount() + SysUtils.Object2Long(map.get("payAmount")));
					statisCharge.setChargeCount(statisCharge.getChargeCount() + SysUtils.Object2int(map.get("payCount")));

				} else if (TransactionType.ConsumptionBackCash.getType() == SysUtils.Object2int(map.get("transaction_type"))) {
					statisCharge.setChargeAmount(statisCharge.getChargeAmount() + SysUtils.Object2Long(map.get("payAmount")));
					statisCharge.setChargeCount(statisCharge.getChargeCount() + SysUtils.Object2int(map.get("payCount")));
					statisCharge.setSaleChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
					statisCharge.setSaleChargeCount(SysUtils.Object2int(map.get("payCount")));
				} else if (TransactionType.RechargeBackCash.getType() == SysUtils.Object2int(map.get("transaction_type"))) {
					statisCharge.setChargeAmount(statisCharge.getChargeAmount() + SysUtils.Object2Long(map.get("payAmount")));
					statisCharge.setChargeCount(statisCharge.getChargeCount() + SysUtils.Object2int(map.get("payCount")));
					statisCharge.setRedpackageChargeAmount(0L);
					statisCharge.setRedpackageChargeCount(0);
				}
			}

			// 查询充值的明细
			// 查询 充值 ，消费送 ，充值送 红包送 的交易
			long actulChargeAmount = 0L;
			List<Map<String, Object>> chargeResult = tradeOfflineMapper.selectStaticChargeBySubTypePayType(statisDateStr, statisDateStr, groupId);
			for (Map<String, Object> map : chargeResult) {
				if (PaymentScene.AppOut.getType() == SysUtils.Object2int(map.get("sub_type"))) {

					if (PaymentType.AliPay.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setAlipayotherChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
						statisCharge.setAlipayotherChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getAlipayotherChargeAmount();
					} else if (PaymentType.WebChat.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setWxpayotherChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
						statisCharge.setWxpayotherChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getWxpayotherChargeAmount();
					}
				} else if (PaymentScene.POS.getType() == SysUtils.Object2int(map.get("sub_type"))) {

					if (PaymentType.BankCard.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setPosbankChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
						statisCharge.setPosbankChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getPosbankChargeAmount();
					} else if (PaymentType.Cash.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setPoscashChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
						statisCharge.setPoscashChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getPoscashChargeAmount();
					}

				} else if (PaymentScene.Scan.getType() == SysUtils.Object2int(map.get("sub_type"))) {
					if (PaymentType.AliPay.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setAlipayChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
						statisCharge.setAlipayChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getAlipayChargeAmount();

					} else if (PaymentType.WebChat.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setWxpayposChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
						statisCharge.setWxpayposChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getWxpayposChargeAmount();
					}
				} else if (PaymentScene.Online.getType() == SysUtils.Object2int(map.get("sub_type"))) {
					if (PaymentType.NetBankCardQuick.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setNetbankChargeAmount(SysUtils.Object2int(map.get("payAmount")));
						statisCharge.setNetbankChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getNetbankChargeAmount();
					} else if (PaymentType.WebChat.getType() == SysUtils.Object2int(map.get("pay_type"))) {
						statisCharge.setWxpayChargeAmount(SysUtils.Object2Long(map.get("payAmount")));
						statisCharge.setWxpayChargeCount(SysUtils.Object2int(map.get("payCount")));
						actulChargeAmount = actulChargeAmount + statisCharge.getWxpayChargeAmount();
					}
				}
			}
			statisCharge.setActulChargeAmount(actulChargeAmount);
			if (statisCharge.getId() != null && statisCharge.getId() > 0) {
				statisChargeMapper.updateByPrimaryKey(statisCharge);
			} else {
				statisChargeMapper.insert(statisCharge);
			}
		}
	}

	@Override
	public ChargeReportInfoListOutDTO chargeReportInfoList(BaseReportInDTO baseReportInDTO) throws Exception {
		ChargeReportInfoListOutDTO chargeReportInfoListOutDTO=new ChargeReportInfoListOutDTO();
		Map<String,Object> staticResult=null;
		List<ChargeOrderBean> chargeOrders=null;
		if(StringUtils.isNotBlank(baseReportInDTO.getSelectDay())){
			String startDate=baseReportInDTO.getSelectDay();
			String endDate=baseReportInDTO.getSelectDay();
			staticResult=statisChargeMapper.selectStaticInfo(startDate,endDate,baseReportInDTO.getGroupId());
			chargeOrders=tradeOfflineMapper.selectChargePaySuccessByGroupId(startDate,endDate,baseReportInDTO.getGroupId());
		}else{
			String startDate=baseReportInDTO.getSelectMonth()+"-01";
			String endDate=baseReportInDTO.getSelectMonth()+"-31";
			staticResult=statisChargeMapper.selectStaticInfo(startDate,endDate,baseReportInDTO.getGroupId());
			chargeOrders=tradeOfflineMapper.selectChargePaySuccessByGroupId(startDate,endDate,baseReportInDTO.getGroupId());
		}
		
		chargeReportInfoListOutDTO.setChargeOrders(chargeOrders);
		if(staticResult!=null){
			chargeReportInfoListOutDTO.setBankChargeAmount(SysUtils.Object2Long(staticResult.get("bankChargeAmount")));
			chargeReportInfoListOutDTO.setBankChargeCount(SysUtils.Object2Integer(staticResult.get("bankChargeCount")));
			chargeReportInfoListOutDTO.setQrcodeChargeAmount(SysUtils.Object2Long(staticResult.get("qrcodeChargeAmount")));
			chargeReportInfoListOutDTO.setQrcodeChargeCount(SysUtils.Object2Integer(staticResult.get("qrcodeChargeCount")));
			chargeReportInfoListOutDTO.setCashChargeAmount(SysUtils.Object2Long(staticResult.get("cashChargeAmount")));
			chargeReportInfoListOutDTO.setCashChargeCount(SysUtils.Object2Integer(staticResult.get("cashChargeCount")));
			chargeReportInfoListOutDTO.setRebackChargeAmount(SysUtils.Object2Long(staticResult.get("rebackChargeAmount")));
			chargeReportInfoListOutDTO.setRebackChargeCount(SysUtils.Object2Integer(staticResult.get("rebackChargeCount")));
			
		}else{
			chargeReportInfoListOutDTO.setBankChargeAmount(0L);
			chargeReportInfoListOutDTO.setBankChargeCount(0);
			chargeReportInfoListOutDTO.setQrcodeChargeAmount(0L);
			chargeReportInfoListOutDTO.setQrcodeChargeCount(0);
			chargeReportInfoListOutDTO.setCashChargeAmount(0L);
			chargeReportInfoListOutDTO.setCashChargeCount(0);
			chargeReportInfoListOutDTO.setRebackChargeAmount(0L);
			chargeReportInfoListOutDTO.setRebackChargeCount(0);
		}
		
		chargeReportInfoListOutDTO.setErrorCode(Rescode.SUCCESS, "成功");
		return chargeReportInfoListOutDTO;
	}

	@Override
	public ChargeReportListOutDTO chargeReportList(BaseReportInDTO baseReportInDTO) throws Exception {
		ChargeReportListOutDTO chargeReportListOutDTO=new ChargeReportListOutDTO();
		String startDate=baseReportInDTO.getSelectMonth()+"-01";
		String endDate=baseReportInDTO.getSelectMonth()+"-31";
		Map<String,Object> staticResult=statisChargeMapper.selectStaticInfo(startDate,endDate,baseReportInDTO.getGroupId());
		if(staticResult!=null){
			chargeReportListOutDTO.setBankChargeAmount(SysUtils.Object2Long(staticResult.get("bankChargeAmount")));
			chargeReportListOutDTO.setBankChargeCount(SysUtils.Object2Integer(staticResult.get("bankChargeCount")));
			chargeReportListOutDTO.setQrcodeChargeAmount(SysUtils.Object2Long(staticResult.get("qrcodeChargeAmount")));
			chargeReportListOutDTO.setQrcodeChargeCount(SysUtils.Object2Integer(staticResult.get("qrcodeChargeCount")));
			chargeReportListOutDTO.setCashChargeAmount(SysUtils.Object2Long(staticResult.get("cashChargeAmount")));
			chargeReportListOutDTO.setCashChargeCount(SysUtils.Object2Integer(staticResult.get("cashChargeCount")));
			chargeReportListOutDTO.setRebackChargeAmount(SysUtils.Object2Long(staticResult.get("rebackChargeAmount")));
			chargeReportListOutDTO.setRebackChargeCount(SysUtils.Object2Integer(staticResult.get("rebackChargeCount")));
		
			
			List<StatisChargeReportBean> resultList= statisChargeMapper.selectByGroupIdAndDate(startDate,endDate,baseReportInDTO.getGroupId());;
			chargeReportListOutDTO.setStatisCharge(resultList);
		}else{
			chargeReportListOutDTO.setBankChargeAmount(0L);
			chargeReportListOutDTO.setBankChargeCount(0);
			chargeReportListOutDTO.setQrcodeChargeAmount(0L);
			chargeReportListOutDTO.setQrcodeChargeCount(0);
			chargeReportListOutDTO.setCashChargeAmount(0L);
			chargeReportListOutDTO.setCashChargeCount(0);
			chargeReportListOutDTO.setRebackChargeAmount(0L);
			chargeReportListOutDTO.setRebackChargeCount(0);
		
		}
		
		chargeReportListOutDTO.setErrorCode(Rescode.SUCCESS, "成功");
		return chargeReportListOutDTO;
	}

	@Override
	public ChargeReportExportListOutDTO chargeReportExportList(BaseReportInDTO baseReportInDTO) {
		ChargeReportExportListOutDTO chargeReportListOutDTO=new ChargeReportExportListOutDTO();
		String startDate=baseReportInDTO.getSelectMonth()+"-01";
		String endDate=baseReportInDTO.getSelectMonth()+"-31";
		Map<String,Object> staticResult=statisChargeMapper.selectStaticInfo(startDate,endDate,baseReportInDTO.getGroupId());
		if(staticResult!=null){
			chargeReportListOutDTO.setBankChargeAmount(SysUtils.Object2Long(staticResult.get("bankChargeAmount")));
			chargeReportListOutDTO.setBankChargeCount(SysUtils.Object2Integer(staticResult.get("bankChargeCount")));
			chargeReportListOutDTO.setQrcodeChargeAmount(SysUtils.Object2Long(staticResult.get("qrcodeChargeAmount")));
			chargeReportListOutDTO.setQrcodeChargeCount(SysUtils.Object2Integer(staticResult.get("qrcodeChargeCount")));
			chargeReportListOutDTO.setCashChargeAmount(SysUtils.Object2Long(staticResult.get("cashChargeAmount")));
			chargeReportListOutDTO.setCashChargeCount(SysUtils.Object2Integer(staticResult.get("cashChargeCount")));
			chargeReportListOutDTO.setRebackChargeAmount(SysUtils.Object2Long(staticResult.get("rebackChargeAmount")));
			chargeReportListOutDTO.setRebackChargeCount(SysUtils.Object2Integer(staticResult.get("rebackChargeCount")));
		
			
			List<StatisCharge> statisCharges= statisChargeMapper.selectInfoByGroupIdAndDate(startDate,endDate,baseReportInDTO.getGroupId());;
			chargeReportListOutDTO.setStatisCharges(statisCharges);
		}else{
			chargeReportListOutDTO.setBankChargeAmount(0L);
			chargeReportListOutDTO.setBankChargeCount(0);
			chargeReportListOutDTO.setQrcodeChargeAmount(0L);
			chargeReportListOutDTO.setQrcodeChargeCount(0);
			chargeReportListOutDTO.setCashChargeAmount(0L);
			chargeReportListOutDTO.setCashChargeCount(0);
			chargeReportListOutDTO.setRebackChargeAmount(0L);
			chargeReportListOutDTO.setRebackChargeCount(0);
		
		}
		
		chargeReportListOutDTO.setErrorCode(Rescode.SUCCESS, "成功");
		return chargeReportListOutDTO;
	}
	
}
